import { Steps } from 'antd';
import React, { useState } from 'react';
import '../../index.css';
import BasicInfoForm from './BasicInfoForm';
import StartEntrance from './StartEntrance';

const { Step } = Steps;

const steps = ["号码验证", "门禁申请"]

export default function AddStudentEntrance(props: any) {

    const [current, setcurrent] = useState(0)


    const [info, setInfo] = useState<any>(null)

    //下一步
    function onNext() {
        setcurrent(current + 1)
    }

    //回到上一步
    function onPrev() {
        setcurrent(current - 1)
    }


    //第一步验证通过
    function onVerifySuccess(value: any) {
        setInfo(value);
        onNext();
    }

    //第二步验证通过
    function submitBasicInfo(value: any) {

        onNext();
        const data = [];
        data[0] = {
            ...value,
            userName: value.userName,
            credentialsNum: value.credentialsNum,
            credentialsTypeId: value.credentialsTypeId,
            sex: value.sex,
            blackCardCode: value.openType.blackCardCode,
            whiteCardCode: value.whiteCardCode,
            staffNum: value.staffNum,
            applyDate: value.applyDate,
            pictureRealName: value.openType.face ? value.facePic[0].response.files[0].fileName : null,
            pictureStoreName: value.openType.face ? value.facePic[0].response.files[0].fileStoreName : null

        }
        // console.log(data)
        setInfo({ ...info, basicInformation: data, healthCodeState: value.healthCodeState });

        // console.log(data)

    }

    //最后一步验证通过
    function onSubmit() {
        props.addSuccess();
    }

    // console.log(info)


    return (
        <div>
            <Steps
                // type="navigation"
                current={current}
            // onChange={value => { setcurrent(value) }}
            >{
                    steps.map((item: string, index: number) => <Step title={item} key={index} />)
                }
            </Steps>
            <br />
            <br />
            <br />
            {current === 0 ? <StartEntrance onVerifySuccess={onVerifySuccess} info={info} />
            :  <BasicInfoForm info={info} onPrev={onPrev} onSubmit={onSubmit}   />}


        </div>
    )
}
